package net.lab1024.sa.admin.module.aneswork.schedule;

import java.util.List;

import net.lab1024.sa.admin.module.aneswork.schedule.domain.entity.StudentScheduleEntity;
import net.lab1024.sa.admin.module.aneswork.schedule.domain.form.StudentScheduleAddForm;
import net.lab1024.sa.admin.module.aneswork.schedule.domain.form.StudentScheduleQueryForm;
import net.lab1024.sa.admin.module.aneswork.schedule.domain.form.StudentScheduleUpdateForm;
import net.lab1024.sa.admin.module.aneswork.schedule.domain.vo.StudentScheduleVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.lab1024.sa.base.common.util.SmartRequestUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 轮转表 Service
 *
 * @Author fwj
 * @Date 2025-04-29 15:32:59
 * @Copyright 1.0
 */

@Service
public class StudentScheduleService {

    @Resource
    private StudentScheduleDao studentScheduleDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<StudentScheduleVO> queryPage(StudentScheduleQueryForm queryForm) {
        queryForm.setStudentId(SmartRequestUtil.getRequestUser().getUserId());
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<StudentScheduleVO> list = studentScheduleDao.queryPage(page, queryForm);
        PageResult<StudentScheduleVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(StudentScheduleAddForm addForm) {
        StudentScheduleEntity studentScheduleEntity = SmartBeanUtil.copy(addForm, StudentScheduleEntity.class);
        studentScheduleDao.insert(studentScheduleEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(StudentScheduleUpdateForm updateForm) {
        StudentScheduleEntity studentScheduleEntity = SmartBeanUtil.copy(updateForm, StudentScheduleEntity.class);
        studentScheduleDao.updateById(studentScheduleEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Integer> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        studentScheduleDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Integer id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        studentScheduleDao.deleteById(id);
        return ResponseDTO.ok();
    }

    public List<StudentScheduleVO> list(@Valid StudentScheduleVO queryForm) {
        List<StudentScheduleVO> list = studentScheduleDao.list(queryForm);
        return list;
    }
}
